<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ersv
 * Date: 12/7/12
 * Time: 10:56 AM
 * To change this template use File | Settings | File Templates.
 */
class EML_EMyLink
{
    /*
    * tạo view để truyền dữ liệu xuống template
    */
    protected $request;
    protected $module;
    protected $action;
    protected $class;
    protected $application;
    public $lang;
    public function __construct($request,$module,$action,$class,$application)
    {
        $this->request=$request;
        $this->module=$module;
        $this->action=$action;
        $this->class=$class;
        $this->application=$application;
    }
    public function getApplicationName()
    {
        return $this->application;
    }
    public function getModuleName()
    {
        return $this->module;
    }
    public function getActionName()
    {
        return $this->action;
    }
    public function getClassName()
    {
        return $this->class;
    }
    public function getRequest($name,$value="")
    {
        return AutoLoader_EMyLink::checkValueArray($name,$value,$this->request);
    }
}
class View_EMyLink
{
    protected $EML;
    protected $LAYOUT;
    protected $SECURE;
    public $view;
    public function __construct($LAYOUT,$EML,$SECURE)
    {
        $this->EML=$EML;
        $this->LAYOUT=$LAYOUT;
        $this->SECURE=$SECURE;
        $this->runAction($EML,$LAYOUT);
        $this->loadLayout();
    }
    /*
     * khởi chạy action
     */
    protected function runAction($EML,$LAYOUT)
    {
        $class=$EML->getModuleName()."_".$EML->getActionName();
        $action=new $class($EML,$LAYOUT);
        $action->run();
        $this->view=$action;
    }
    /*
     * load layout
     */
    protected function loadLayout()
    {
        if($this->LAYOUT->has_layout)
        {
            if(file_exists(ROOT_PATH."/application/".$this->EML->getApplicationName()."/layout/".$this->LAYOUT->layout.".php"))
            {
                require_once(ROOT_PATH."/application/".$this->EML->getApplicationName()."/layout/".$this->LAYOUT->layout.".php");
            }
        }
        else
        {
            require_once(ROOT_PATH."/application/".$this->EML->getApplicationName()."/module/".$this->EML->getModuleName()."/template/".$this->EML->getActionName().".template.php");
        }
    }
    /*
     * sử dụng để gọi content cho layout
     */
    public function content()
    {
        require_once(ROOT_PATH."/application/".$this->EML->getApplicationName()."/module/".$this->EML->getModuleName()."/template/".$this->EML->getActionName().".template.php");
    }
    /*
     * sử dụng để add block
     */
    public function block($file)
    {
        require_once(ROOT_PATH."/application/".$this->EML->getApplicationName()."/block/".$file);
    }
}
